package com.xinqi.modules.prepare.video.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.prepare.video.client.PrepareVideoPointClient;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoPointCreateDTO;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoPointQueryDTO;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoPointUpdateDTO;
import com.xinqi.modules.prepare.video.dto.rsp.PrepareVideoPointResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 备课区互动视频环节降级处理
 *
 * @author: system
 * @date: 2023/03/19
 */
@Slf4j
@Component
public class PrepareVideoPointFallbackFactory implements FallbackFactory<PrepareVideoPointClient> {

    @Override
    public PrepareVideoPointClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new PrepareVideoPointClient() {
            @Override
            public R<PageInfo<PrepareVideoPointResultDTO>> page(PrepareVideoPointQueryDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<PrepareVideoPointResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Long> insert(PrepareVideoPointCreateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> update(Long id, PrepareVideoPointUpdateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> delete(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}
